//
//  OGLApp.cpp
//  GSP420_Week3_iLab
//
//  Created by Scott Nelson on 5/18/11.
//  Copyright 2011 NA. All rights reserved.
//

#include "OGLApp.h"


//Constructor
OGLApp* OGLApp::Instance()
{
    static OGLApp instance;
    return &instance;
}

//Destructor
OGLApp::~OGLApp(){};


//Initialization functions
bool OGLApp::onInit() 
{
    /*
     This section will include the code to initialize all OpenGL subsystems
     as well as initialize all of the other cores.
     */

    //Set display properties
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //Set up a display buffer, enable double buffering, blending and depth testing
    glutInitWindowSize(1000, 1000); //Set the width and height of the window
    glutInitWindowPosition(100, 100); //Set window position
    glutCreateWindow("GSP 420"); //Set window caption
    
    return true;
}

//Checks for events and sends messages to the update function
void OGLApp::onEvent()
{
    /*
     This section will listen for events and dispatch the appropriate
     message for the events that occur.
     */
    
    printf("\nonEvent");
}

//Receives events from the onEvent function and updates game objects
void OGLApp::onUpdate()
{
    /*
     This section will call the proper update functions to update the
     game objects for variables such as position or health.
     */
    
    printf("\nonUpdate");
}

//Renders objects to the screen
void OGLApp::onRender()
{
    
    //Handle drawing
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //Clear background of window
    glClear(GL_COLOR_BUFFER_BIT); //Clear the color buffer
    glLoadIdentity(); //Load identity matrix to reset drawing locations
    
    //Translate scene back
    glTranslatef(0.0f, 0.0f, -6.0f);
    
	glPushMatrix();
    glRotatef(rotationAngle, 0.0, 1.0, 0.0);
    
    //Draw an object
    //===========================================================
    //THIS FUNCTION IS TEMPORARY AND FOR TESTING ONLY
    //The render function will be the one doing the real drawing. 
    //===========================================================
    GraphicsObject::drawObject(CUBE); //TEMPORARY - Objects will NOT draw themselves. 
    
	glPopMatrix();
    
	rotationAngle++; //Rotation angle for pyramid
    
    glutSwapBuffers();
}

//Exits program and destroys objects
void OGLApp::onExit()
{
    /*
     This section will call the proper functions to
     destroy objects, free allocated memory, and destroy
     the singleton
     */
    
    printf("\nonExit");
    OGLApp::~OGLApp(); 
    printf("\nDestructor Called");
}
